//
//  JMRepaymentModel.m
//  NewiOSProject
//
//  Created by JMMac on 18.1.24.
//  Copyright © 2024 范智渊. All rights reserved.
//

#import "JMRepaymentModel.h"
@implementation PayCodeModel
-(NSString *)barcodeUrlAlfa{
    if (_barcodeUrlAlfa !=nil && _barcodeUrlAlfa.length>0) {
        return _barcodeUrlAlfa;
    }else{
        return nil;
    }
}

-(NSString *)payTypeString{
    
    if(self.payType==1){
        return @"BANCOS";
    }
    if(self.payType==2){
        return @"OXXO";
    }
    if(self.payType==3){
        return @"OpenPay";
    }
    return @"";
}

@end



@implementation delayTermModel

@end




@implementation JMRepaymentModel
+(NSDictionary *)mj_objectClassInArray{
    return @{@"repaymentCodeList":PayCodeModel.class};
}
-(NSString *)payTypeString{
    if(self.payType==1){
        return @"BANCOS";
    }
    if(self.payType==2){
        return @"OXXO";
    }
    if(self.payType==3){
        return @"OpenPay";
    }
    return @"";
}

-(PayCodeModel *)leftPayModel{
    if (self.repaymentCodeList.count==0) {
        if (self.openPayCode) {
            PayCodeModel *mod = self.openPayCode;
            mod.payType = 3;
            return mod;
        }else{
            return nil;
        }
    }else if(self.repaymentCodeList.count==1){
        PayCodeModel *mod = self.repaymentCodeList.firstObject;
        mod.payType = mod.repaymentBank.isOXXO?2:1;
        return mod;
    }else{
        PayCodeModel *bancos;
        BOOL TwoOXXO = YES;
        for (PayCodeModel *model in self.repaymentCodeList) {
            if(![model.repaymentBank isOXXO]){//左侧优先返回非OXXO的数据
                TwoOXXO = NO;
                bancos = model;
            }
        }
        if(TwoOXXO){
            bancos = self.repaymentCodeList.firstObject;
            bancos.payType = 2;
        }else{
            bancos.payType = 1;
        }
        return bancos;
    }
}
- (PayCodeModel *)rightModel{
    if (self.openPayCode) {
        PayCodeModel *mod = self.openPayCode;
        mod.payType = 3;
        return mod;
    }else if(self.repaymentCodeList.count==2){
        PayCodeModel *mod;
        BOOL containOXXO = NO;
        for (PayCodeModel *model in self.repaymentCodeList) {
            if([model.repaymentBank isOXXO]){//左侧优先返回非OXXO的数据
                containOXXO = YES;
                mod = model;
                mod.payType = 2;
            }
        }
        if (containOXXO==NO) {
            mod = self.repaymentCodeList.lastObject;
            mod.payType = 1;
        }
        return mod;
    }else{
        return nil;
    }
}




//
//-(NSString *)LoanType{
//    if(self.status.intValue == 90 || self.status.intValue == 100){//En revisión 审批中
//        return @"UNDER_REVIEW";
//    }
//    if(self.status.intValue == 150){//Depositando 放款中
//        return @"LENDING";
//
//    }
//    if(self.status.intValue == 170){//Pendiente de reembolso 待还款=放款成功
//        return @"TO_REPAID";
//
//    }
//    if(self.status.intValue == 180){//Reembolso atrasado 逾期还款
//        return @"OVERDUE";
//    }
//    if(self.status.intValue == 200){//Reembolsado 贷款结清=已还款
//        return @"REPAID";
//    }
//   
//    return @"";
//}

@end
